package com.zrrd.jt_admin.set.express.controller;


import com.zrrd.jt_admin.common.entity.Express;
import com.zrrd.jt_admin.common.response.ResponseResult;
import com.zrrd.jt_admin.common.vo.ExpressPageVo;
import com.zrrd.jt_admin.set.express.service.ExpressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Zhangyk
 * @since 2024-07-02
 */
@Api(tags = "运费模板管理-接口文档")
@RestController
@RequestMapping("admin/express")
@ResponseBody
public class ExpressController {

    @Resource
    private ExpressService expressService;

    @ApiOperation(value = "一、获取运费模板列表的分页数据")
    @GetMapping("{page}")
    public ResponseResult findByPage(@PathVariable Integer page,
                                     @RequestParam(value = "limit",required = false)Integer limit) {
        if (limit==null){
            limit = 5;
        }
        ExpressPageVo expressPageVo = expressService.findByPage(page,limit);
        return ResponseResult.queryResponse(expressPageVo);
    }

    @ApiOperation(value = "二、增加运费模板")
    @PostMapping
    public ResponseResult addExpress(@RequestBody Express express) {
        if (express==null){
            return ResponseResult.addResponse(false);
        }
        return ResponseResult.addResponse(expressService.save(express));
    }

    @ApiOperation(value = "三、修改运费模板")
    @PutMapping
    public ResponseResult updateExpress(@RequestBody Express express) {
        if (express==null){
            return ResponseResult.updateResponse(false);
        }
        return ResponseResult.updateResponse(expressService.updateById(express));
    }

    @ApiOperation(value = "四、删除运费模板")
    @DeleteMapping("{id}/delete")
    public ResponseResult deleteExpress(@PathVariable Integer id) {
        return ResponseResult.removeResponse(expressService.removeById(id));
    }

}

